package leetcode;

public class Code6 {

    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 3, 4, 5,6,7,8,9,10};
        int[] b = new int[]{2, 3, 4, 5, 6};
        int[] c = new Code6().mergeSortedArray(a, b);
        for (int aa = 0; aa < c.length; aa++) {
            System.out.print(" " + c[aa]);
        }
    }

    public int[] mergeSortedArray(int[] A, int[] B) {
        // write your code here
        int[] C = new int[A.length + B.length];
        int ai = 0;
        int bi = 0;
        for (int a = 0; a < C.length; a++) {
            if ( ai < A.length&&(bi == B.length || A[ai] <= B[bi])) {
                C[a] = A[ai];
                ai++;
            } else if (bi<B.length){
                C[a] = B[bi];
                bi++;
            }
        }
        return C;
    }
}